﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using Airport;
using System.Diagnostics;

namespace AirportConfigurator.Formatters
{
    public class RunwayNameFormatter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Runway input = (Runway)value;

            return input.Direction1 + "/" + input.Direction2;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class DoubleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {            
            string sourceValue = value.ToString();
            Debug.WriteLine("Convert: value.ToString() = " + value.ToString());
            Double decimalValue = 0;
            
            if (Double.TryParse(sourceValue, out decimalValue))
            {
                Debug.WriteLine("Convert: decimalValue.ToString() = " + decimalValue.ToString());
                return decimalValue;
            }
            
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string sourceValue = value.ToString();
            Debug.WriteLine("ConvertBack: value.ToString() = " + value.ToString());
            Double decimalValue = 0;

            if (Double.TryParse(sourceValue, out decimalValue))
            {
                Debug.WriteLine("ConvertBack: decimalValue.ToString() = " + decimalValue.ToString());
                return decimalValue;
            }
            return value;
        }
    }
}
